print("==========Loops===============")
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
for planet in planets:
    print(planet, end='-')  # print all on same line

"""
The for loop specifies

the variable name to use (in this case, planet)
the set of values to loop over (in this case, planets)
You use the word "in" to link them together.

The object to the right of the "in" can be any object that supports iteration. 
Basically, if it can be thought of as a group of things, you can probably loop over it. 
In addition to lists, we can iterate over the elements of a tuple:
"""
print("\n")
multiplicands = (2, 2, 2, 3, 3, 5)
product = 3
for mult in multiplicands:
    product = product * mult
    print(product, end=" ")

# loop in string
print("\n")
s = 'steganograpHy is the practicE of conceaLing a file, message, image, or video within another fiLe, message, image, Or video.'
msg = ''
# print all the uppercase letters in s, one at a time
for char in s:
    if char.isupper():
        print(char, end='')

"""
range()
range() is a function that returns a sequence of numbers. It turns out to be very useful for writing loops.

For example, if we want to repeat some action 5 times:
"""
print("\n")
for i in range(3):
    print("Doing important work. i =", i)  # i=0,1,2

"""
while loops
The other type of loop in Python is a while loop, which iterates until some condition is met.
The argument of the while loop is evaluated as a boolean statement,
and the loop is executed until the statement evaluates to False.
"""
fruits = ['apple', 'pear', 'peach', 'banana', 'mango']
while len(fruits) > 3:
    fruit = fruits.pop()
    print(fruit)

i = 0
while i < 10:
    print(i * 2)
    i += 2

"""
List comprehensions
List comprehensions are one of Python's most beloved and unique features. 
The easiest way to understand them is probably to just look at a few examples:
"""
print("=============List comprehensions=====================")
squ = [n ** 2 for n in range(5)]
for num in squ:
    print(num, end="__")
print("\n")
# the same as
squares = []
for n in range(5):
    squares.append(n ** 2)

# We can also add an if condition:
long_planets = [planet for planet in planets if len(planet) >= 7]
print(long_planets)

# str.upper() returns an all-caps version of a string
loud_short_planets = [
    (planet.upper() + "$").endswith("1")
    for planet in planets
    if len(planet) >= 5
]  # find the structure clearer when it's split up over 3 lines:
print(loud_short_planets)

what_is_that = ["???" for p in planets]
print(what_is_that)

"""
List comprehensions combined with functions like min, max, and sum can lead to 
impressive one-line solutions for problems that would otherwise require several lines of code.
"""


def count_negatives(nums):
    """Return the number of negative numbers in the given list.

    >>> count_negatives([5, -1, -2, 0, 3])
    2
    """
    n_negative = 0
    for num1 in nums:
        if num1 < 0:
            n_negative = n_negative + 1
    return n_negative


def count_negatives1(nums):
    return len([num2 for num2 in nums if num2 < 0])


def count_negatives2(nums):
    # Reminder: in the "booleans and conditionals" exercises, we learned about a quirk of
    # Python where it calculates something like True + True + False + True to be equal to 3.
    return sum([NUM < 0 for NUM in nums])
